from pydantic import BaseModel
from typing import Optional
from datetime import datetime
class UserLogin(BaseModel):
    username: str
    password: str
    phone:str | None = None

class UserCreate(BaseModel):
    username: str
    password: str
    email: str | None = None
    phone: str | None = None
    user_type: str = "普通用户"
    login_type: str = "本地"
    third_party_id: str | None = None
    third_party_account: str | None = None
    third_party_phone: str | None = None
    avatar: str | None = None
    balance: float = 0.00
    addresses: list = []
    membership_level: int | None = None


class UserOut(BaseModel):
    id: int
    username: str
    email: str | None
    phone: str | None
    user_type: str
    login_type: str
    third_party_id: str | None
    third_party_account: str | None
    third_party_phone: str | None
    create_time: datetime
    update_time: datetime
    avatar: str | None

    class Config:
        from_attributes = True 
        json_encoders = {
            datetime: lambda dt: dt.isoformat()
        }

class UserUpdate(BaseModel):
    username: Optional[str] = None
    email: Optional[str] = None
    password: Optional[str] = None
    phone: Optional[str] = None
    user_type: Optional[str] = None
    login_type: Optional[str] = None
    third_party_id: Optional[str] = None
    third_party_account: Optional[str] = None
    third_party_phone: Optional[str] = None
    membership_level: Optional[int] = None

class Token(BaseModel):
    access_token: str
    token_type: str

class TokenData(BaseModel):
    username: str
    password: str
    token: str